package io.github.rascaler.dcenter.exception;

import io.github.rascaler.dcenter.message.ErrorMessageManager;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @ClassName BaseException
 * @Description TODO
 * @Author wurenqing
 * @Date 2022/7/11 8:56
 */
@Accessors(chain = true)
@Data
public class BaseException extends RuntimeException {
    public static ErrorMessageManager messageManager = null;

    /** 状态码 */
    private String ecode;

    /** 状态码说明 */
    private String msg;

    /** 数据 */
    private Object data;

    public BaseException() {};

    public BaseException(String ecode) {
        String msg = messageManager.getMsg(ecode);
        this.ecode = ecode;
        this.msg = msg;
    }

    public BaseException(String ecode, Object... args) {
        this.ecode = ecode;
        this.msg = messageManager.getMsg(ecode);
        if (args != null && args.length > 0) {
            this.msg = String.format(this.msg, args);
        }
    }

    @Override
    public String toString() {
        return "BizException{" +
                "ecode=" + ecode +
                ", msg='" + msg + '\'' +
                '}';
    }
}
